<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
    <h4>填入数据库得到的字段例如    id, user_id   转变为 id as id,user_id as userId,就是加as</h4>
    <textarea id="text1" placeholder="`id`,user_id,`user_name`,`user_login_name`" style="width: 1000px;height: 40px"></textarea>
</div>
<div>
    <button style="background-color: #00F7DE" onclick="dianjibiantuofeng()">点击变驼峰和as</button>
</div>
<div>
    <h4>加完as并驼峰</h4>
    <textarea id="text2" style="width: 1000px;height: 40px"></textarea>
</div>
<div>
    <button style="background-color: #00F7DE" onclick="dainjibianprivatestring()">点击变private String</button>
</div>
<div>
    <h4>加完private String并驼峰</h4>
    <textarea id="text3" style="width: 1000px;height: 40px"></textarea>
</div>
<script type="text/javascript">

    function dainjibianprivatestring() {
        let w=dianjibiantuofeng();
        let s="";
        let strs = w.split(",");
        for(let i=0;i<strs.length;i++){
            let strss = strs[i];
            let k = strss.split("as");
            let m = k[1];
            while(m.indexOf(" ")>=0){
                m=m.replace(" ","");
            }
            while(m.indexOf("\n")>=0){
                m=m.replace("\n","");
            }
            s=s+"private"+" "+"String"+" "+m+";"+"\n";
        }

        document.getElementById("text3").innerHTML=s;


    }




    function dianjibiantuofeng(){
        let t1 = document.getElementById("text1").value;
        t1=t1.replace(" ","");
        while (true){
            if(t1.indexOf('`')>=0){
                t1=t1.replace("`","");
            }else {
                break;
            }
        }

        let ss = t1.split(",");
        let sss="";
        for(let i=0;i<ss.length;i++){
            //如果包含
            if(ss[i].indexOf("_")>=0){
                let ssss=chuli(ss[i]);
                sss=sss+ss[i]+" as "+ssss+",";
            }else{
                //如果不包含
                sss=sss+ss[i]+" as "+ss[i]+",";
            }
        }
        if(sss.endsWith(",")){
            sss=sss.substring(0,sss.lastIndexOf(","))
        }
        sss=sss.replace("        "," ");
        sss=sss.replace("       "," ");
        sss=sss.replace("\n     "," ");
        sss=sss.replace("\n","");

        while(true){
            if(sss.indexOf("  ")>=0){
                sss=sss.replace("  "," ");
            }else{
                break;
            }
        }
        document.getElementById("text2").innerHTML=sss;
        if(!sss.startsWith(" ")){
            sss=" "+sss;
        }
        if(!sss.endsWith(" ")){
            sss=sss+" ";
        }
        return sss;
    }
    function chuli(str) {
        //此时str包含有_
        let s="";
        let split = str.split("_");
        for (let i=0;i<split.length;i++){
            if(i===0){
                s=s+split[i];
            }else{
                let x = split[i];
                let k = x.substring(0,1);
                 k=k.toUpperCase();
                let p=k+x.substring(1)
                s=s+p;
            }
        }
        return s;
    }
</script>
</body>
</html>